<template>
	<view id="ownerRule">
		<view class="vote-title">
			{{voteDetailInfo.community_name}} 首次业主大会通知
		</view>
		<view class="vote-title sub-title">
			还有 {{diffTimeInfo.timeCha}} 投票开始
		</view>
		<view class="vote-content">
			<view class="content">
				<view >
					<span
						style="margin-left: 35px;font-size: 14px;letter-spacing: 3px;line-height: 1.8;color: black;font-weight: bolder">

						{{voteDetailInfo.city}}
						{{voteDetailInfo.district}}
						根据《物业管理条例》
						{{voteDetailInfo.city+'物业管理条例》'}}及《业主大会和业主委员会指导规则》等相关规定，
						{{voteDetailInfo.vote_type == 1 ?'筹备组' : '委托人'}}已完成本小区修订《议事规则》《业主规约》的草案，
						并决定选择业委会委员{{voteDetailInfo.four_members_number}}名，后补委员{{voteDetailInfo.four_replenish_members_number}}名。
					</span>
				</view>
				<view style="margin-top: 10px">
					<span
						style="margin-left: 35px;font-size: 14px;letter-spacing: 3px;line-height: 1.8;color: black;font-weight: bolder">
						现决定在{{voteDetailInfo.preparations_start_time}}召开首次业主大会会议，
						确定以上事项，会议采用《助业平台》电子投票和线下纸质投票两种方式。
						会议时间共计{{dateDifference(voteDetailInfo.preparations_start_time,voteDetailInfo.preparations_end_time)}}天，于{{voteDetailInfo.preparations_end_time}}结束。
					</span>
				</view>
			</view>
		</view>
		<view class="vote-item" v-for="(item, index) in fileList">
			<view class="vote-mr">
				<view class="title">
					{{item.statute_state == 1 ? '业主规约' 
					: item.statute_state == 2 ? '议事规则'
					: item.statute_state == 3 ? '召开业主大会方案'
					: item.statute_state == 4 ? '认证委员方案'
					: item.statute_state == 5 ? '其他文件'
					: ''
					}}
				</view>
				<text class="middle">
					<image class="word" src="/static/vote/word.png"></image>
				</text>
				<text class="right" @click="viewDoctor(item.statute_img)">{{item.file_name}}</text>
				<view class="agree-btn" @click="viewComment(item)">
					查看评论
				</view>
			</view>
		</view>
		<view>
			<view style="padding: 20px 0 30px 20px;background-color: #F8F8F8;display: flex;">
				<image style="width: 40px;height: 40px;" src="/static/vote/group.png"></image>
				<u-cell-item style="padding: 10px 20px 0 10px;font-size: 18px;font-weight: 800;" @click="goToDetail"
					:title="voteDetailInfo.vote_type == 1 ?'委员候选人公示' : '委托人公示'"></u-cell-item>
			</view>
		</view>
		<br>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				voteId: null, //表决id
				fileList: [],
				voteDetailInfo: {},
				//剩余时间详细
				diffTimeInfo: {},
			}
		},
		onLoad(option) {
			this.voteId = option.id
			this.getFileList();
			this.getVoteDetailInfoById();
		},
		methods: {
			//计算两个日期差值（天）
			dateDifference(sDate1, sDate2) { //sDate1和sDate2是2006-12-18格式
				let dateSpan, tempDate, iDays
				sDate1 = Date.parse(sDate1)
				sDate2 = Date.parse(sDate2)
				dateSpan = sDate2 - sDate1
				dateSpan = Math.abs(dateSpan)
				iDays = Math.floor(dateSpan / (24 * 3600 * 1000))
				return iDays
			},
			//获取表决投票类型 1.附议 2.筹备组报名
			getVoteDetailInfoById() {
				this.$requestYz.api.getVoteDetailInfo({
					id: this.voteId,
					selectPassNumber: 1
				}).then(res => {
					if (res.data.data.voteInfo) {
						this.voteDetailInfo = res.data.data.voteInfo;
						this.getTimeDiffInfo();
					}
				})
			},
			//获取剩余时间
			getTimeDiffInfo() {
				this.$requestYz.api.getDiffTime({
					endTime: this.voteDetailInfo.six_holding_time + ' 00:00:00'
				}).then(res => {
					this.diffTimeInfo = res.data.data;
				})
			},
			getFileList() {
				this.$requestYz.api.getFileList({
					essential_information_id: this.voteId,
					fileSelect: 1,
				}).then(res => {
					this.fileList = res.data.data.datalist;
				})
			},
			//显示文档
			viewDoctor(url) {
				uni.downloadFile({
					url: url,
					success: function(res) {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
							},
							fail() {
								console.log('打开文档失败');
							}
						});
					}
				});
			},
			goToDetail() {
				uni.navigateTo({
					url: `/pages/vote/components/publicity/nameList?id=${this.voteId}&typeName=2`
				})
			},
			//查看评论
			viewComment(item) {
				console.log(item)
				uni.navigateTo({
					url: `/pages/vote/components/publicity/viewComment?id=${item.id}&file_name=${item.file_name}&file_url=${item.statute_img}&voteId=${item.essential_information_id}&fileType=${item.statute_state}`
				})

			}
		}
	}
</script>

<style lang="scss">
	$color:#999;
	$bold:bold;

	::v-deep .u-collapse-head {
		font-size: 32rpx !important;
		font-weight: bold !important;
		margin: 10rpx 46rpx;
	}


	#ownerRule {
		min-height: 100vh;
		height: auto;
		background-color: #f4f4f4;
		padding-top: 20rpx;



		.vote-content {
			margin-top: 40rpx;
			width: 100%;
			height: 330px;
			background: #FFFFFF;
			box-shadow: 0px 1px 0px 0px #EEEEEE;

			.content {
				padding: 50rpx;
				font-size: 32rpx;
				font-weight: bold;
			}
		}

		.vote-title {
			font-size: 36rpx;
			font-weight: bold;
			margin: 0 auto 60rpx;
			text-align: center;
			padding-top: 40rpx;
		}

		.sub-title {
			font-size: 28rpx;
			margin-top: -30px;
			font-weight: $bold;
			color: $color;
		}

		.vote-item {
			width: 100%;
			min-height: 274rpx;
			background: #f4f4f4;
			padding: 20rpx 0;

			.vote-mr {
				padding: 30rpx 46rpx;
				background-color: #FFFFFF;
			}

			.vote-status {
				color: #427705;
				font-size: 28rpx;
				font-weight: bold;
				text-align: center;
			}

			.vote-line {
				width: 345px;
				height: 1px;
				border: 1px solid #EEEEEE;
				margin: 30rpx auto;
			}

			.title {
				font-size: 28rpx;
				font-weight: bold;
				margin-bottom: 30rpx;
			}

			.middle {
				margin: 30rpx 0;
			}

			.right {
				margin-left: 46rpx;
				color: #4C77F2;
				font-weight: $bold;
				text-decoration: underline;
			}

			.word {
				width: 80rpx;
				height: 90rpx;
				vertical-align: middle;
			}

			.agree-btn {
				width: 176rpx;
				height: 60rpx;
				background: linear-gradient(180deg, #76D904 0%, #417505 100%);
				border-radius: 44rpx;
				color: #fff;
				text-align: center;
				line-height: 31px;
				margin-left: 72%;
			}
		}
	}
</style>
